package com.pams.controller;


import com.pams.pojo.entity.Msg;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/ai")
public class AIChatController {

    @Autowired
    private final ChatClient chatClient;

    @RequestMapping(value = "/chat", produces = "text/html;charset = utf-8")
    public Flux<String> chat(@RequestBody Msg msg) {
        String prompt = msg.getPrompt();
        String system = msg.getSystem();
        return chatClient.prompt()
                .user(prompt + system)
                .system("你是个人事务管理系统的AI助手," +
                        "前端程序可能会发送用户的日记信息，当收到的prompt信息" +
                        "为：‘已发送相关信息’，这时你别说用户没有发送任何信息，程序里已经" +
                        "自动放入system里面，并且开始分析，回答用户，根据日记或笔记基于用户" +
                        "生活上的建议,还有不要提及用户的用户名")
                .stream()
                .content();

    }

}
